﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Baimasoft.FrameWork.Base;
using Baimasoft.Manage.SqlServerDAL;

public partial class BBS_ReTopic_Edit : System.Web.UI.Page
{
    protected string str1, str2, str3, str4, Name = "", SID, SName, AID, AName, RepliesID;
    CommClass MyCC = new CommClass();
    user Myuser = new user();
    Articles MyAT = new Articles();
    Replies MyRl = new Replies();
    

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            SID = Request.QueryString["SectionID"].ToString().Trim();
            SName = Request.QueryString["SectionName"].ToString().Trim();
            AID = Request.QueryString["ArticleID"].ToString().Trim();
            AName = MyCC.FilterBadWords(Request.QueryString["ArticleName"].ToString().Trim());
            RepliesID = Request.QueryString["RepliesID"].ToString().Trim();
        }
        catch
        {
            Response.Write("参数传递错误！");
            Response.End();
        }

        if (!this.IsPostBack)
        {
            SqlDataReader MyDr = MyRl .ReadRepliesInfo (RepliesID);
            if (MyDr.Read())
            {
                Content.Text = MyDr["Content"].ToString().Trim();
            }
        }
    }
    protected void Submit_Click(object sender, ImageClickEventArgs e)
    {
        str1 = Content.Text.ToString().Trim();
        if (str1 == "")
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('回复内容不能为空！');</script>");
            return;
        }
        else
        {
            string TheMaster;
            DataView MasterInfo = new DataView();
            TheMaster = Myuser.GetMasterUser(SID);
            string[] sStr1 = TheMaster.Split(',');
            TheMaster = sStr1[0];

            string UserName = (string)Session["Baimasoft_User_LogonID"]; 

            string sArticleAuthor = Myuser.GetArticleAuthor(AID);  //当前主题贴作者
            string sReArticleAuthor = Myuser.GetReArticleAuthor(RepliesID);  //当前回复者
            int state;
            if ((UserName == "admin") || (UserName == TheMaster) || (UserName == sArticleAuthor) || (UserName == sReArticleAuthor))
            {
                state = 1;
                string UserIP = Request.UserHostAddress;
                string UserDNS = Request.UserHostName;
                int back = MyRl.UpdateReplieSelf (str1, UserIP, UserDNS,  RepliesID);
                if (back == 1)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功！');location.href='Articles_List.aspx?SectionID=" + SID + "&ArticleID=" + AID + "&SectionName=" + SName + "&ArticleName=" + AName + "'</script>");
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改失败！');</script>");
                    return;
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('您无些权限！');</script>");
                return;
            }
        }
    }
    protected void Reset_Click(object sender, ImageClickEventArgs e)
    {

    }
}
